import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_audit_app/res/colors.dart';
import 'package:flutter_audit_app/res/strings.dart';

///  项目名称：flutter_audit_app
///  Created by leon on 2020/10/20 .

///  封装输入框
///
typedef void OnSubmit(String content);

class InputEditText extends StatelessWidget {
  final String _title;
  final int _maxLength;
  final bool _isShowColon;
  final TextInputType _keyboardType;
  final String _hintText;
  final OnSubmit _onSubmit;
  final TextEditingController _controller = new TextEditingController();

  InputEditText(
    String title, {
    OnSubmit onSubmit,
    int maxLength,
    String hintText,
    TextInputType keyboardType,
    bool isShowColon = true,
  })  : _title = title,
        _onSubmit = onSubmit,
        _hintText = hintText ?? Strings.hintInputTxt,
        _maxLength = maxLength,
        _keyboardType = keyboardType ?? TextInputType.text,
        _isShowColon = isShowColon;

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      // constraints: BoxConstraints(),
      child: Row(
        // mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Text(
            _isShowColon ? '$_title：' : _title,
            style: TextStyle(fontSize: 11),
          ),
          ConstrainedBox(
            constraints: BoxConstraints(
              maxHeight: height(40),
              maxWidth: width(200),
            ),
            child: TextField(
              controller: _controller,
              maxLines: 1,
              maxLength: _maxLength,
              decoration: InputDecoration(
                border: InputBorder.none,
                //去掉下划线
                contentPadding: EdgeInsets.only(top: 1, left: 5),
                hintText: _hintText,
                hintStyle: TextStyle(
                  fontSize: 10,
                  color: Colours.u_b3b3b3,
                ),
                focusedBorder: OutlineInputBorder(
                  gapPadding: 0,
                  borderSide: BorderSide(
                    color: Colors.blue.shade500, //获取焦点后输入框边框颜色
                    width: width(0.7),
                  ),
                ),
                enabledBorder: OutlineInputBorder(
                  gapPadding: 0,
                  borderSide: BorderSide(
                    color: Colors.grey, //默认输入框边框颜色
                    width: width(0.7),
                  ),
                ),
              ),
              textInputAction: TextInputAction.done,
              keyboardType: _keyboardType,
              onSubmitted: (string) => _onSubmit(string),
            ),
          ),
        ],
      ),
    );
  }
}
